import {
    defineComponent,
    resolveComponent,
    type PropType
} from 'vue'

import { type formField } from "../type.d";

import baseComponents from "../base/index";

export default defineComponent({
    name: 'wt_formItem',
    components: { ...baseComponents },
    props: {
        dataObj: { type: Object, default: () => ({}), required: false },
        fieldConfig: { type: Object as PropType<formField>, required: true }
    },

    setup(props, ctx) {
        const fieldElement = resolveComponent(props.fieldConfig.type);
        return () => (
            <a-form-item label={props.fieldConfig.title} name={props.fieldConfig.name}>
                <fieldElement placeholder={props.fieldConfig.placeholder || '请输入'.concat(props.fieldConfig.title)} dataObj={props.dataObj} name={props.fieldConfig.name} fieldConfig={props.fieldConfig.config}></fieldElement>
            </a-form-item>
        )
    }
})
